/**
 * @param {string} s
 * @return {string[]}
 */
var printVertically = function (s) {
  let arr = s.split(' '),
    res = []
  let row = arr.length
  let col = 0,
    str = ''
  for (const s of arr) {
    col = Math.max(col, s.length)
  }
  for (let i = 0; i < col; i++) {
    str = ''
    for (let j = 0; j < row; j++) {
      str += arr[j][i]? arr[j][i]:' '
    }
    res.push(str.trimEnd(' '))
  }

  return res
}

printVertically('TO BE OR NOT TO BE')
